/**
 * 
 */
package com.wsd.action.admin;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.apache.struts2.json.annotations.JSON;

import com.opensymphony.xwork2.ActionContext;
import com.wsd.action.BaseAction;
import com.wsd.bean.Message;
import com.wsd.bean.ProductComment;
import com.wsd.service.CommentService;
import com.wsd.util.PagingBuilder;
import com.wsd.util.SysUtil;

/**
 * @author Administrator
 *
 */
public class CommentAction extends BaseAction {
	private CommentService commentService;
	private int total;
	private int start;
	private int limit;
	private int page = 1;
	
	private ProductComment comment;
	private ProductComment replay;
	
	@JSON(serialize = false)
	public CommentService getCommentService() {
		return commentService;
	}

	public void setCommentService(CommentService commentService) {
		this.commentService = commentService;
	}
	@JSON(serialize = false)
	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}
	@JSON(serialize = false)
	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}
	@JSON(serialize = false)
	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}
	@JSON(serialize = false)
	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}
	
	@JSON(serialize = false)
	public ProductComment getComment() {
		return comment;
	}

	public void setComment(ProductComment comment) {
		this.comment = comment;
	}
	@JSON(serialize = false)
	public ProductComment getReplay() {
		return replay;
	}

	public void setReplay(ProductComment replay) {
		this.replay = replay;
	}

	public String show(){
		//System.out.println("取得留言：：：：：");
		//ActionContext.getContext().put("messages", "hello world");
		List<ProductComment> comments = commentService.findAll((page - 1)*5,5);
		String pageStr = PagingBuilder.build("/wsd/admin/comment_show.action?page=@page@", page, 10, (commentService.findAllCount() - 1)/5 + 1);
		ActionContext.getContext().put("comments", comments);
		ActionContext.getContext().put("pageStr", pageStr);
		ActionContext.getContext().put("curPage", page);
		return SUCCESS;
	}
	 
	public String replay(){
		replay.setPCTime(new Timestamp(new Date().getTime()));
		replay.setAdmin(SysUtil.currentAdmin());
		replay.setPCState(true);//设为已回复
		replay.setComment(commentService.findById(comment.getPCId()));
		commentService.saveReplay(replay);
		result.put("id", replay.getPCId());
		return AJAX;
	}
	
	public String delete(){
		commentService.deleteById(replay.getPCId());
		ActionContext.getContext().put("page", page);
		return "delete";
	}
	
	
	
}
